package entidades;

import util.*;
import java.util.List;
import java.util.LinkedList;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author JFM
 */
public class OrdenVentaView
	{
	public static String VISTA = "ordenes_venta_view";
	
	public static List<OrdenVenta> buscar(String where) throws SQLException
		{
		List<OrdenVenta> lista;
		ResultSet result = MySQL.executeQuery("SELECT * FROM " + VISTA + " WHERE " + where);
		lista = leer(result);
		return lista;
		}

	public static List<OrdenVenta> leer(ResultSet result) throws SQLException
		{
		List<OrdenVenta> res = new LinkedList();
		while(result.next())
			{
			OrdenVenta ov = new OrdenVenta(result);
			ov.setEstado(new EstadoVenta(result, "ev_"));
			ov.setLinea(new Linea(result, "li_"));
			ov.setLacaUv(new LacaUv(result, "lu_"));
			ov.setLogotipo(new Logotipo(result, "lo_"));
			ov.setManija(new Manija(result, "ma_"));
			ov.setTipoPapel(new TipoPapel(result, "tp_"));
			ov.setAltaUsuario(new Usuario(result, "us_"));
			res.add(ov);
			}
		result.getStatement().close();
		return res;
		}
	/*
	public static void main(String args[]) throws SQLException
		{
		boolean usarVista = true;
		
		for(int i=0; i<200; i++)
			{
			ResultSet result = MySQL.executeQuery("SELECT * FROM " + (usarVista? VISTA : OrdenVenta.NOMBRE_TABLA));
			
			while(result.next())
				{
				OrdenVenta ov = new OrdenVenta(result);
				if(usarVista)
					{
					ov.setEstado(new EstadoVenta(result, "ev_"));
					ov.setLinea(new Linea(result, "li_"));
					ov.setLacaUv(new LacaUv(result, "lu_"));
					ov.setLogotipo(new Logotipo(result, "lo_"));
					ov.setManija(new Manija(result, "ma_"));
					ov.setTipoPapel(new TipoPapel(result, "tp_"));
					ov.setAltaUsuario(new Usuario(result, "us_"));
					}
				
				System.out.println(
					ov.getId() + ": " + 
					ov.getEstado() + " - " +
					ov.getLinea() + " - " + 
					ov.getLacaUv() + " - " + 
					ov.getLogotipo() + " - " +
					ov.getManija() + " - " + 
					ov.getTipoPapel() + " - " + 
					ov.getAltaUsuario());
				}
			}		
		}
	*/
	}
